*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*
*Generated: 2025-11
*
*by Lukas Rudolph
*
*modified: --
*
*Data used: ukr_vignette.dta
*Data output generated: conjoint reshape; recoded variables (PCA scores and derived indices/indicators)
*
*Tables generated: --
*Figutes generated: --
*
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


******************************************************** 
*This file presents code we used to 
*-- reshape the data in long format 
*==> can be used to reshape the ukr_vignette.dta data in wide form to the ukr_conjoint.dta in long form), 
*-- code to construct the PCA scores, and derive indices/indicators from it (PCA scores/indices/indicator variables) 
* ==> can be used to generate scores/indices from the raw data. 
* ==> NOTE: these are already conatained in the data file, for the code to run you need to drop the variables with identical name before generating them anew)
********************************************************

********************************************************
*This file only provides background and is not necessary to run before reproducing our analyses with the other scripts provided
********************************************************

********************************************************
*Prepare Stata
********************************************************

*load data
use ukr_master_and_vignette_replication_data.dta, clear

*drop variables generated by this do-file
drop country-slight_prowestern  




********************************************************
*PCA indices
********************************************************

gen country = Country

**** pro-/anti-Western attitudes // transatlanticism 
recode Q11 (977=.)

gen pro_russia = q16_13 
replace pro_russia = q17_15 if q16_13 ==.

gen anti_us = q16_12 
replace anti_us = q17_14 if q16_12 == .

pca pro_russia anti_us Q11 [aweight=W8], factor(1)
 rotate
predict anti_west

**** attitudes towards war and peace
pca q16_? q16_10 [aweight=W8], factor(2)
rotate
predict pacifist hawk

**** foreign policy values
pca q17_?  q17_12 [aweight=W8], factor(3)
rotate
predict coop mil iso  


********************************************************
*define binary indicators for split-sample regressions
********************************************************

*** pro-/anti-Western
sum anti_west, d
gen antiwestern = anti_west >= `r(p75)' & anti_west <.
replace antiwestern = . if anti_west == .

sum anti_west, d
gen prowestern = anti_west <= `r(p25)' & anti_west <.
replace prowestern = . if anti_west == .

sum anti_west, d
gen slight_antiwestern = anti_west < `r(p75)' & anti_west >= `r(p50)' 
replace slight_antiwestern = . if anti_west == .

sum anti_west, d
gen slight_prowestern = anti_west > `r(p25)' & anti_west < `r(p50)' 
replace slight_prowestern = . if anti_west == .

*** 2-dimensional war-peace scale
sum pacifist, d
gen pacifistic = pacifist >= `r(p75)' & pacifist <.
replace pacifistic = . if pacifist == .

sum hawk, d
gen hawkish = hawk >= `r(p75)' & hawk <.
replace hawkish = . if hawk == .

sum pacifist, d
gen no_pacifistic = pacifist <= `r(p25)' & pacifist <.
replace no_pacifistic = . if pacifist == .

sum hawk, d
gen no_hawkish = hawk <= `r(p25)' & hawk <.
replace no_hawkish = . if hawk == .

*** 3-dimensional foreign policy values 

sum coop, d
gen cooperator = coop >= `r(p75)' & coop <.
replace cooperator = . if coop == .

sum mil, d
gen interventionist = mil >= `r(p75)' & mil <.
replace interventionist = . if mil == .

sum iso, d
gen isolationist = iso >= `r(p75)' & iso <.
replace isolationist = . if iso == .

sum coop, d
gen no_cooperator = coop <= `r(p25)' & coop <.
replace no_cooperator = . if coop == .

sum mil, d
gen no_interventionist = mil <= `r(p25)' & mil <.
replace no_interventionist = . if mil == .

sum iso, d
gen no_isolationist = iso <= `r(p25)' & iso <.
replace no_isolationist = . if iso == .


********************************************************
*reshape conjoint
********************************************************

gen id = _n

reshape long q2_attr1_concept@_task1 q2_attr1_concept@_task2 q2_attr1_concept@_task3 q2_attr1_concept@_task4 ///
q2_attr2_concept@_task1 q2_attr2_concept@_task2 q2_attr2_concept@_task3 q2_attr2_concept@_task4  ///
q2_attr3_concept@_task1 q2_attr3_concept@_task2 q2_attr3_concept@_task3 q2_attr3_concept@_task4  ///
q2_attr4_concept@_task1 q2_attr4_concept@_task2 q2_attr4_concept@_task3 q2_attr4_concept@_task4  ///
q2_attr5_concept@_task1 q2_attr5_concept@_task2 q2_attr5_concept@_task3 q2_attr5_concept@_task4  ///
q2_attr6_concept@_task1 q2_attr6_concept@_task2 q2_attr6_concept@_task3 q2_attr6_concept@_task4  ///
q2_attr7_concept@_task1 q2_attr7_concept@_task2 q2_attr7_concept@_task3 q2_attr7_concept@_task4  ///
q2_attr8_concept@_task1 q2_attr8_concept@_task2 q2_attr8_concept@_task3 q2_attr8_concept@_task4  ///
q2_attr9_concept@_task1 q2_attr9_concept@_task2 q2_attr9_concept@_task3 q2_attr9_concept@_task4  ///
Q12B1_@ Q12B2_@ Q12B3_@ Q12B4_@ ///
 , i(id) j(concept)


reshape long q2_attr1_concept_task@ ///
q2_attr2_concept_task@  ///
q2_attr3_concept_task@  ///
q2_attr4_concept_task@  ///
q2_attr5_concept_task@  ///
q2_attr6_concept_task@  ///
q2_attr7_concept_task@  ///
q2_attr8_concept_task@  ///
q2_attr9_concept_task@  ///
Q12A@  Q12B@ Q12B@_ tie1task@ tie2task@ tie3task@ tie4task@ tie5task@ tie6task@ tie7task@ tie8task@ tie9task@ ///
 , i(id concept) j(task)


*gen choice indicator
gen choice = 0  if concept != Q12A
replace choice = 1 if concept == Q12A 
fre choice


********************************************************
*conjoint attribute labels
********************************************************

label variable q2_attr1_concept_task "Number of Ukrainian soldiers killed?"
tab q2_attr1_concept_task 
d q2_attr1_concept_task
label define attr1 1 "12,500" 2 "25,000" 3 "50,000", replace
label values q2_attr1_concept_task attr1
tab q2_attr1_concept_task 

label variable q2_attr2_concept_task "Number of Russian soldiers killed?"
tab q2_attr2_concept_task 
label define attr2 1 "25,000" 2 "50,000" 3 "100,000", replace
label values q2_attr2_concept_task attr2 
tab q2_attr2_concept_task 

label variable q2_attr3_concept_task "Number of Ukrainian civilians killed?"
tab q2_attr3_concept_task 
d q2_attr3_concept_task
label define attr3 1 "4,000" 2 "8,000" 3 "16,000", replace
label values q2_attr3_concept_task attr3 
tab q2_attr3_concept_task 

label variable q2_attr4_concept_task "Value of destroyed infrastructure in Ukraine?"
tab q2_attr4_concept_task 
d q2_attr4_concept_task
label define attr4 1 "$50B" 2 "$100B" 3 "$200B", replace
label values q2_attr4_concept_task attr4 
tab q2_attr4_concept_task 

label variable q2_attr5_concept_task "[Country] contribution to military aid to Ukraine?"
tab q2_attr5_concept_task 
d q2_attr5_concept_task
label define attr5 1 "0.1% of GDP" ///
           2 "0.2% of GDP" ///
           3 "0.3% of GDP", replace
label values q2_attr5_concept_task attr5
tab q2_attr5_concept_task 

label variable q2_attr6_concept_task "[Country] contribution to economic aid to Ukraine?"
tab q2_attr6_concept_task 
d q2_attr6_concept_task
label define attr6 1 "0.1% of GDP" ///
           2 "0.2% of GDP" ///
           3 "0.3% of GDP", replace
label values q2_attr6_concept_task attr6
tab q2_attr6_concept_task 

label variable q2_attr7_concept_task "Risk of a Russian nuclear strike on Ukraine?"
tab q2_attr7_concept_task 
d q2_attr7_concept_task
label define attr7 1 "Not present (0%)" 2 "Low (5%)" 3 "Moderate (10%)", replace
label values q2_attr7_concept_task attr7
tab q2_attr7_concept_task 

label variable q2_attr8_concept_task "Territorial cessions of Ukraine to Russia?"
tab q2_attr8_concept_task 
d q2_attr8_concept_task
label define attr8 1 "None" ///
2 "Crimea (4%)" ///
3 "2014 LoC (8%)" ///
4 "2023 LoC (16%)", replace
label values q2_attr8_concept_task attr8
tab q2_attr8_concept_task 

label variable q2_attr9_concept_task "How much political self-determination of Ukraine?"
tab q2_attr9_concept_task 
d q2_attr9_concept_task
label define attr9 1 "Full" ///
2 "No EU/NATO" ///
3 "Russian influence", replace
label values q2_attr9_concept_task attr9
tab q2_attr9_concept_task 



********************************************************
*simpler variable version
********************************************************

foreach x in 1 2 3 4 5 6 7 8 9 {
gen ukr_attr`x' = q2_attr`x'_concept_task 
local label : variable label q2_attr`x'_concept_task 
label variable ukr_attr`x' "`label'"
label values ukr_attr`x' attr`x'
}



